package com.example.stujava.module.xiangxue.reflect.generic_type;


import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.GenericDeclaration;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;

public class TypeVariableStu<K extends Comparable<String> & Serializable, V> {
    private K key;
    V value;

    public static void main(String[] args) throws Exception {
        Class<TypeVariableStu> cla = TypeVariableStu.class;
        Field field = cla.getDeclaredField("key");
        Field field2 = cla.getDeclaredField("value");
        //属性名称
        System.out.println(field.getName() + " " + field.getType());
        System.out.println(field2.getName() + " " + field2.getType());//value java.lang.Object
        TypeVariable genericType2 = (TypeVariable) field.getGenericType();
        Type genericType = field2.getGenericType();
        System.out.println(genericType2.getName()); //V
        //getGenericDeclaration
        GenericDeclaration genericDeclaration = genericType2.getGenericDeclaration();
        System.out.println(genericDeclaration);//class com.example.stujava.module.xiangxue.reflect.generic_type.TypeVariableStu
        //getBounds
        System.out.println("K 的上界");
        for (Type type : genericType2.getBounds()) {
            System.out.println(type);//java.lang.Comparable<java.lang.String> ,interface java.io.Serializable
        }

    }
}
